<?php
/**
 * Admin - View Associa Contatto a Partner - LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    16-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript">
    //<![CDATA[
    function selectable(){
	$('a[id^="link-contact"]').click(function(){
            var id = $(this).attr('id');

            $.ajax({
                url: '/admin/ajax/add/contacttopartner/id/'+id.substr(13,id.length),
                context: document.body
                }).success(function(data) { 
                    $('#selected_contacts').append(data);
                    unselectable();
                }).error(function(obj,text,error) {
                   //show error
                   $('li#errorLi').show();
                   $('li#errorLi p#errorMsg').html(obj.responseText);
                });
            })
    };

    function unselectable(){
        $('a[id^="unlink-contact"]').click(function(){
            $(this).parents('tr.unselectable').remove();
	})
    };
     
    $(document).ready(function()
    {
        var paginator =	$('#contacts').pagination({
	    'targetUrl' : '/admin/ajax/list/contactsmini',
	    'orderField' : 'contact_name',
	    'orderDir' : 'asc'
	},selectable // CallBack
        );

	$("#new").fancybox({
	    'type' : 'ajax',
	    'showCloseButton' : false
	});
        
	// Lancio unselectable per i contatti eventualmente già presenti...
	unselectable();
    });

    //]]>
</script>
<div class="info">
    <h2>Associa Contatto</h2>
    <div>Per inserire un nuovo post...</div>
    <div>I campi contrassegnati da <span class="req">*</span> sono obbligatori!</div>
</div>
<form id="form-invia" method="post" action="/admin/partners/associacontatti/id/<?php echo $this->partner_id ?>">
    <ul id="paging-live">
        <li class="paging-context ">
        <table class="pgStyle1 circle2" cellspacing="0">
            <tr>
                <td class="c">
                    <var>1</var>
                </td>
                <td class="t">
                    <b id="pagecircle1"><a href="/admin/contatti/info/id/<?php echo $this->partner_id ?>">Dettagli Partner</a></b>
                </td>
                <td class="c selected">
                    <var>2</var>
                </td>
                <td class="t selected">
                    <b id="pagecircle2">Associa Contatti</b>
                </td>
            </tr>
        </table>
        </li>
    </ul>
    <div id="content">
        <div id="summary" class="contact">
            <div class="head contact">
                <h2>Riepilogo Partner:</h2>
            </div>
            <div class="body">
                <table cellspacing="0" class="table">
                    <tbody>
                        <tr>
                            <th>Nome:</th>
                            <td>
                                <strong>
                                <?php echo $this->data['partner_name'] ?>
                                </strong>
                            </td>
                        </tr>
                        <tr>
                            <th>Email Principale:</th>
                            <td>
                                <strong>
                                <?php echo $this->data['partner_email'] ?>
                                </strong>
                            </td>
                        </tr>
                        <tr>
                            <th>Telefono Principale:</th>
                            <td>
                                <strong>
                                <?php echo $this->data['partner_phone'] ?>    
                                </strong>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>        
        <ul>
            <li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none' ?>">
                <h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
                <p id="errorMsg">
                    <?php echo $this->errorMsg ?>
                </p>
            </li>	
        </ul>

        <div id="detailTableLeft">
            <ul>
                <li id="fo2li107" class="likert col2">
                    <table cellspacing="0">
                        <caption id="title107">
                            Clicca per Selezionare:
                        </caption>                                                
                        <thead>
                            <tr>
                                <td colspan="5" class="pagination">
                                    <div class="paginator">
                                        <span class="prev">
                                            <a href="javascript: void(0);">&nbsp;</a>
                                        </span>
                                        <span class="loader">Sto caricando...</span>
                                        <span class="next">
                                            <a href="javascript: void(0);">&nbsp;</a>
                                        </span>
                                    </div>
                                </td>
                            </tr>		    
                            <tr>
                                <th class="sortable default {ref: 'contact_name'}">Nome</th>
                                <td colspan="3">&nbsp;</td>
                            </tr>
                        </thead>
                        <tbody id="contacts">
                            <!-- Questo contenuto verrà rimpiazzato dalla paginazione-->
                        </tbody>
                    </table>
                </li>
            </ul>
        </div>	
        <div id="detailTableRight">
            <ul>
                <li id="fo2li107" class="likert col2">
                    <table cellspacing="0">
                        <caption id="title107">
                            Clicca per Deselezionare:
                        </caption>                        
                        <thead>
                            <tr>
                                <td colspan="4">&nbsp;</td>
                            </tr>		    
                        </thead>
                        <tbody id="selected_contacts">
			<!-- Questo contenuto verrà rimpiazzato dalla paginazione-->
			<?php
			if( count( $this->data['partner_contacts'] ) ):
			    foreach( $this->data['partner_contacts'] AS $contact ) : ?>
			    <tr class="unselectable" id="contact_<?php echo $contact['contact_id'] ?>">
				<th>
				    <span><?php echo $contact['contact_firstname'] ?> <?php echo $contact['contact_lastname'] ?></span>
				    <div class="details">
					<h4><strong>Tel: </strong> <?php echo $contact['contact_phone'] ?></h4>
					<h4><strong>Email: </strong> <?php echo $contact['contact_email'] ?></h4>
				    </div>
				</th>
				<td>
				    <ul>
					<li class="complex">
					    <span class="left">
						<label>Ruolo:</label>
						<select class="field select addr" name="contacts[<?php echo $contact['contact_id'] ?>][]" id="contact_<?php echo $contact['contact_id'] ?>">
						<?php foreach( $this->contact_roles AS $k => $role ) : ?>
						    <option value="<?php echo $k ?>" <?php echo ( $k == $contact['fab_contacts_role'] ) ? 'selected="selected"' : '' ?>><?php echo $role ?></option>
						<?php endforeach; ?>
						</select>
					    </span>
					</li>
				    </ul>
				</td>
				<td title="Operazioni">
				    <span class="actions">
					<a class="del" id="unlink-contact-<?php echo $contact['contact_id']?>" href="#">
					    &nbsp;
					</a>
				    </span>
				</td>
			    </tr>
			    <?php endforeach;
                            else:
                                ?><tr class="result"><td colspan="5">Nessun elemento presente...</td></tr> <?php	
                            endif;?>			
                        </tbody>
                    </table>		
                    <input type="hidden" name="conferma" id="conferma" value="conferma" />
                </li>
            </ul>
        </div>
        <br style="clear: both" />
        <ul>
            <li class="section">
                <h3>Oppure:</h3>
                <ul>
                    <li class="addnew">
                        <a id="new" class="button" href="/admin/ajax/form/newcontact?">
                            <img src="/images/admin/add-new.png" />Aggiungi Nuovo Contatto (Veloce)
                        </a>
                    </li>
                </ul>
            </li>
        </ul>    
    </div>
    <div id="formButtons">
        <button id="salva" name="salva" value="salva" class="button positive">
            <img src="/images/admin/tick.png" alt="" />Continua
        </button>
        <a id="annulla" name="annulla" value="annulla" class="button negative" href="#">
            <img src="/images/admin/cross.png" alt="" />Annulla
        </a>
    </div>
</form>